package cn.wolfcode.web.hander;

import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.net.ssl.HandshakeCompletedListener;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Component
public class Hander implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        System.out.println(handler.getClass());
        if (handler instanceof HandlerMethod) {
            HttpSession session = request.getSession();
            if (session.getAttribute("USER_SUCCESS") != null){
                return true;
            }
            response.sendRedirect("/login.html");
            return false;
        }
        return true;
    }
}
